<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视差滚动</title>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 150vh;
            overflow-x: hidden;
        }

        .background {
            background-image: url("image/background.jpg");
            background-size: cover;
            background-position: 50% 50%;
            height: 150vh;
            font: 900 39rem '';
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            position: relative;
            text-align: center;
            overflow: hidden;
        }

        .background::before {
            content: '';
            background-size: cover;
            background-image: inherit;
            background-position: 50% 50%;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            z-index: -99;
        }

        h1 {
            position: absolute;
            text-align: center;
            width: 100%;
            letter-spacing: 10px;
            color: #fff;
        }

        h2 {
            position: absolute;
            letter-spacing: 2px;
            top: 120vh;
            width: 60%;
            color: #fff;
            left: 50%;
            transform: translateX(-50%);
            padding: 30px;
            background-color: rgba(0,0,0,.3);
        }
    </style>
</head>

<body>
    <h1>bilibili<br>灯火不休时</h1>
    <div class="background"><span>DHBXS</span></div>
    <h2>
        清弦弹吻一袖风雨，丝丝缕缕涟漪，蘸一缣水墨，将惆怅画在晓风残月的柳堤之上。幽谷之外，是谁，轻舞箫管，余音袅袅，淡淡忧思，轻灵哀婉？是谁，丹青着色，碾尽一池墨香，云影清舞？
    </h2>

    <script>
        const background = document.querySelector(".background");

        document.addEventListener('scroll', () => {
            const scrollY = window.scrollY;
            if (scrollY !== 0) {
                background.style.backgroundPosition = `calc(50% + ${scrollY}px) calc(50% + ${scrollY}px)`;
            }else {
                background.style.backgroundPosition = '';
            }
        })
    </script>
</body>

</html>